private var passionCharge1:int=0;
private var ethicsCharge1:int=0;
private var logicCharge1:int=0;
private var deceptionCharge1:int=0;

private var passionCharge2:int=0;
private var ethicsCharge2:int=0;
private var logicCharge2:int=0;
private var deceptionCharge2:int=0;


var tower1:Tower;
var tower2:Tower;
var player1:PlayerObject;
var player2:AIObject;

//top row
private var chargeWheelRect1:Rect=Rect(20,20,150,150);
private var chargeWheelRect2:Rect=Rect(Screen.width-170,20,150,150);

//bottom row
private var chatRect:Rect=Rect(10, Screen.height-(240+10),400,240);
private var optionsRect:Rect=Rect(Screen.width-(239+20+325+20),Screen.height-(150+10),239,150);
private var quickKeyRect:Rect=Rect(Screen.width-(325+30),Screen.height-(150+10),345,150);



private var confirmRect:Rect=Rect(450,200,200,305);
private var egoRect1:Rect=Rect(175,20,100,30);
private var egoRect2:Rect=Rect(Screen.width-(175+100),20,100,30);
private var towerHeightRect1=Rect(65,350,125,20);
private var towerHeightRect2=Rect(Screen.width-(65+125),350,125,20);
private var messageRect=Rect(450,450,100,20);
private var centerStyle=new GUIStyle();

private var timeStart;
private var timeElapsed;
private var messageEnabled=false;
private var messageText:String;
private var messageLength:int;

private var startTime;
private var restSeconds : int;
private var roundedRestSeconds : int;
private var displaySeconds : int;
private var displayMinutes : int;
private var timerEnable: boolean=false;
private var timerCheck: boolean=false;

var countDownSeconds : int=15;

private var buttonHandler1;

var skin : GUISkin;

function ShowMessage(inMsg:String,inTime:int){
	messageText=inMsg;
	messageLength=inTime;
	timeStart=Time.time;
	timeElapsed=Time.time;
	messageEnabled=true;
}

function GetChargeNum(teamNum:int, type:String){
	if(teamNum==1){
		if(type=="Passion"){
			return passionCharge1;
		}
		else if(type=="Ethics"){
			return ethicsCharge1;
		}
		else if(type=="Logic"){
			return logicCharge1;
		}
		else if(type=="Deception"){
			return deceptionCharge1;
		}
	}
	else if(teamNum==2){
		if(type=="Passion"){
			return passionCharge2;
		}
		else if(type=="Ethics"){
			return ethicsCharge2;
		}
		else if(type=="Logic"){
			return logicCharge2;
		}
		else if(type=="Deception"){
			return deceptionCharge2;
		}
	}
}
function AddCharge(teamNum:int,type:String)
{
	if (teamNum==1)
	{
		if (type=="Passion")
		{
			passionCharge1++;
			if(passionCharge1>2) passionCharge1=2;
			//print("New Charge: " + passionCharge1);
		}
		if (type=="Ethics")
		{
			ethicsCharge1++;
			if(ethicsCharge1>2) ethicsCharge1=2;
		}
		if (type=="Logic")
		{
			logicCharge1++;
			if(logicCharge1>2) logicCharge1=2;
		}
		if (type=="Deception")
		{
			deceptionCharge1++;
			if(deceptionCharge1>2) deceptionCharge1=2;
		}
	}
	if (teamNum==2)
	{
		if (type=="Passion")
		{
			passionCharge2++;
			if(passionCharge2>2) passionCharge2=2;
		}
		if (type=="Ethics")
		{
			ethicsCharge2++;
			if(ethicsCharge2>2) ethicsCharge2=2;
		}
		if (type=="Logic")
		{
			logicCharge2++;
			if(logicCharge2>2) logicCharge1=2;
		}
		if (type=="Deception")
		{
			deceptionCharge2++;
			if(deceptionCharge2>2) deceptionCharge1=2;
		}
	}
}
			
function LoseCharge(teamNum:int,type:String)
{
	if (teamNum==1)
	{
		if (type=="Passion")
		{
			passionCharge1--;
			if(passionCharge1<0) passionCharge1=0;
		}
		if (type=="Ethics")
		{
			ethicsCharge1--;
			if(ethicsCharge1<0) ethicsCharge1=0;
		}
		if (type=="Logic")
		{
			logicCharge1--;
			if(logicCharge1<0) logicCharge1=0;
		}
		if (type=="Deception")
		{
			deceptionCharge1--;
			if(deceptionCharge1<0) deceptionCharge1=0;
		}
	}
	if (teamNum==2)
	{
		if (type=="Passion")
		{
			passionCharge2--;
			if(passionCharge2<0) passionCharge2=0;
		}
		if (type=="Ethics")
		{
			ethicsCharge2--;
			if(ethicsCharge2<0) ethicsCharge2=0;
		}
		if (type=="Logic")
		{
			logicCharge2--;
			if(logicCharge2<0) logicCharge1=0;
		}
		if (type=="Deception")
		{
			deceptionCharge2--;
			if(deceptionCharge2<0) deceptionCharge1=0;
		}
	}
}
function OnGUI()
{
	buttonHandler1=this.gameObject.GetComponent("ButtonHandler1");
	centerStyle.alignment=TextAnchor.UpperCenter;
	centerStyle.normal.textColor=Color.white;
	if(messageEnabled){
		GUI.Label(messageRect,messageText,centerStyle);
		timeElapsed+=Time.deltaTime;
		if (timeElapsed>timeStart+messageLength)
		{
			messageEnabled=false;
		}
	}
	GUI.Window(0,chargeWheelRect1,ChargeWheelUpdater1,"", skin.customStyles[0]); //ChargeWheelUpdater
	GUI.Window(1,chargeWheelRect2,ChargeWheelUpdater2,"", skin.customStyles[0]);
	GUI.Button(chatRect,"Chat Window");
	GUI.Window(2,quickKeyRect,ButtonWindowUpdater,"", skin.customStyles[1]);
	GUI.Window(3,optionsRect,OptionsWindowUpdater,"OptionsWindow:Quit/Timer", skin.customStyles[6]);
	GUI.Window(4,confirmRect,ConfirmWindowUpdater,"", skin.customStyles[3]);
	GUI.Label(egoRect1,"Ego Player1: "+ player1.currentEgo);
	GUI.Label(egoRect2,"Ego Player2: "+player2.currentEgo);
	GUI.Label(towerHeightRect1,"Tower Height 1: "+ tower1.height);
	GUI.Label(towerHeightRect2,"Tower Height 2: "+ tower2.height);
}
function ChargeWheelUpdater1(windowID:int)
{
	if(passionCharge1==2){
		GUI.Label(Rect(7,7,68,68),"",skin.customStyles[16]);
	}
	else if(passionCharge1==1){
		GUI.Label(Rect(33,33,42,42),"",skin.customStyles[15]);
	}

	
	if(ethicsCharge1==2){
		GUI.Label(Rect(75,7,68,68),"",skin.customStyles[18]);
	}
	else if(ethicsCharge1==1){
		GUI.Label(Rect(75,33,42,42),"",skin.customStyles[17]);
	}
	
	
	if(deceptionCharge1==2){
		GUI.Label(Rect(7,75,68,68),"",skin.customStyles[20]);
	}
	else if(deceptionCharge1==1){
		GUI.Label(Rect(33,75,42,42),"",skin.customStyles[19]);
	}
	
	
	if(logicCharge1==2){
		GUI.Label(Rect(75,75,68,68),"",skin.customStyles[14]);
	}
	else if(logicCharge1==1){
		GUI.Label(Rect(75,75,42,42),"",skin.customStyles[13]);
	}
	
}

function ChargeWheelUpdater2(windowId:int)
{
	if(passionCharge2==2){
		GUI.Label(Rect(7,7,68,68),"",skin.customStyles[16]);
	}
	else if(passionCharge2==1){
		GUI.Label(Rect(33,33,42,42),"",skin.customStyles[15]);
	}

	
	if(ethicsCharge2==2){
		GUI.Label(Rect(75,7,68,68),"",skin.customStyles[18]);
	}
	else if(ethicsCharge2==1){
		GUI.Label(Rect(75,33,42,42),"",skin.customStyles[17]);
	}
	
	
	if(deceptionCharge2==2){
		GUI.Label(Rect(7,75,68,68),"",skin.customStyles[20]);
	}
	else if(deceptionCharge2==1){
		GUI.Label(Rect(33,75,42,42),"",skin.customStyles[19]);
	}
	
	
	if(logicCharge2==2){
		GUI.Label(Rect(75,75,68,68),"",skin.customStyles[14]);
	}
	else if(logicCharge2==1){
		GUI.Label(Rect(75,75,42,42),"",skin.customStyles[13]);
	}
	
}

function ButtonWindowUpdater(windowId:int){
	GUI.Button(Rect(10,10,64,64),"Logic", skin.customStyles[12]);
	GUI.Button(Rect(75,10,64,64),"Passion", skin.customStyles[9]);
	GUI.Button(Rect(140,10,64,64),"Ethic", skin.customStyles[10]);
	GUI.Button(Rect(205,10,64,64),"Decep", skin.customStyles[11]);
	
	if(GUI.Button(Rect(10,75,64,64),"Slot 1", skin.customStyles[8])){
		if(buttonHandler1.GetButtonToggle()){
			buttonHandler1.currentButtonSelected="11";
		}
	}
	if(GUI.Button(Rect(75,75,64,64),"Slot 2", skin.customStyles[8])){
		if(buttonHandler1.GetButtonToggle()){
			buttonHandler1.currentButtonSelected="12";
		}
	}
	if(GUI.Button(Rect(140,75,64,64),"Slot 3", skin.customStyles[8])){
		if(buttonHandler1.GetButtonToggle()){
			buttonHandler1.currentButtonSelected="13";
		}
	}
	if(GUI.Button(Rect(205,75,64,64),"Slot 4", skin.customStyles[8])){
		if(buttonHandler1.GetButtonToggle()){
			buttonHandler1.currentButtonSelected="14";
		}
	}
	if(GUI.Button(Rect(270,75,64,64),"Slot 5", skin.customStyles[8])){
		if(buttonHandler1.GetButtonToggle()){
			buttonHandler1.currentButtonSelected="15";
		}
	}
}

function OptionsWindowUpdater(windowId:int){
	if(timerEnable){	
		var guiTime = Time.time - startTime;

		restSeconds = countDownSeconds - (guiTime);

		//display messages or whatever here -->do stuff based on your timer
		if (restSeconds == 60) {
			print ("One Minute Left");
		}
		if (restSeconds == 0) {
			print ("Time is Over");
			timerEnable=false;
			
			//do stuff here
		}

		//display the timer
		roundedRestSeconds = Mathf.CeilToInt(restSeconds);
		displaySeconds = roundedRestSeconds % 60;
		displayMinutes = roundedRestSeconds / 60; 

		text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 
		GUI.Label (Rect (200, 75, 75, 30), text);
	}
	GUI.Button(Rect(20,70,100,30),"Tie", skin.customStyles[7]);
	if(GUI.Button(Rect(20,110,100,30),"Forfeit", skin.customStyles[7])){
		this.gameObject.GetComponent("GameHandler").player1forfeitCheck=true;
	}
	GUI.Label(Rect(140,30,50,30),"Timer:");
}

function enableTimer() {
    startTime = Time.time;
	timerEnable=true;
	Debug.Log("Starting Timer");
	
}

function ConfirmWindowUpdater(){
	GUI.Button(Rect(20,255,160,30),"Confirm", skin.customStyles[4]);
	GUI.Button(Rect(20,20,160,230),"Button Choice", skin.customStyles[5]);
}
